package com.briup.cms.web.controller;


import com.briup.cms.aop.Logging;
import com.briup.cms.bean.Carousel;
import com.briup.cms.service.ICarouselService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "轮播图相关接口")
@RestController
@RequestMapping("/auth/carousel")
public class CarouselController {

    @Autowired
    private ICarouselService service;

    @ApiOperation("保存轮播图信息")
    @PostMapping("/save")
    public Message save(Carousel c){
        service.saveCarousel(c);
        return MessageUtil.success(c);
    }

    @ApiOperation("根据轮播图id删除轮播图信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "需要删除的轮播图id",dataType = "int")
    })
    @DeleteMapping("/deleteById")
    public Message deleteById(int id){
        service.deleteById(id);
        return MessageUtil.success();
    }


    @ApiOperation("根据轮播图id更新轮播图状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "需要更新的轮播图id",dataType = "int"),
            @ApiImplicitParam(name = "status",value = "需要更新的轮播图status",dataType = "int")
    })
    @PutMapping("/update/status")
    public Message updateStaById(int id,int status){
        System.out.println("service....需要更新的轮播图id"+id);
        service.updateCarouselByStatus(id,status);
        return MessageUtil.success();

    }

    @ApiOperation("根据轮播图id更新轮播图信息")
    @PutMapping("/update")
    public Message updateStaById(Carousel c){
        System.out.println("service....需要更新状态的轮播图id"+c);
        service.updateCarousel(c);
        return MessageUtil.success();
    }


    @Logging
    @ApiOperation("分页查询轮播图信息")
    @GetMapping("/page/query")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "页面大小",dataType = "int",required = true)
    })
    public Message infoPage( int pageNum, int pageSize){

        System.out.println(pageNum+".....controll"+pageSize);
//        System.out.println(1/0);
        return  MessageUtil.success(service.findAll(pageNum,pageSize));
    }


    @ApiOperation("查询已启用的轮播图")
    @GetMapping("/find/yes")
    public Message selectByyesStatus(){

        return  MessageUtil.success(service.findYesCarousel());
    }
}
